<?php
$con = array('dbms' => 'mysql', 'host' => $C->DB_HOST, 'dbName' => $C->DB_NAME,
    'user' => $C->DB_USER, 'pass' => $C->DB_PASS);

interface connectDB
{
    function __construct($con);
    function selectdb($sql);
    function insertdb($sql);
    function updatedb($sql);
    function deletedb($sql);
    function __destruct();
}

abstract class DBoperate implements connectDB
{
    protected $dbh = null;
    function __construct($con)
    {
        $dbms = $con['dbms'];
        $host = $con['host'];
        $dbName = $con['dbName'];
        $dsn = "$dbms:host=$host;dbname=$dbName";
        try {
            $this->dbh = new PDO($dsn, $con['user'], $con['pass']);
            $this->dbh->query("set names utf8");
        }
        catch (PDOException $e) {
            die("Error!: " . $e->getMessage() . "<br/>");
        }
        $this->dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
    }

    function selectdb($sql)
    {
        /**
         * 查询操作；
         */
    }

    function insertdb($sql)
    {
        /**
         *  插入操作；
         */
    }

    function updatedb($sql)
    {
        /**
         * 更新操作；
         */
    }

    function deletedb($sql)
    {
        /**
         *  删除操作；
         */
    }

    function __destruct()
    {
        $this->dbh = null;
    }
    
    function query($sql)
    {
    	
    }

}

class DBservice extends DBoperate
{
    function selectdb($sql)
    {
        $this->dbh->exec($sql);
    }

    function insertdb($sql)
    {
        $this->dbh->exec($sql);
    }

    function updatedb($sql)
    {
        $this->dbh->exec($sql);
    }

    function deletedb($sql)
    {
        $this->dbh->exec($sql);
    }
    
    function query($sql)
    {
    	return $this->dbh->query($sql);
    }

    
}



?>